/*     */package com.vehicle.auto.click.controller;
/*     */
/*     */ import com.vehicle.auto.click.common.FireFDriver;
/*     */ import com.vehicle.auto.click.enums.DataBaseVserionEnum;
/*     */ import com.vehicle.auto.click.form.AutoClickForm;
/*     */ import com.vehicle.auto.click.model.VehicleInfo;
/*     */ import com.vehicle.auto.click.service.VehicleInfoService;
/*     */ import java.io.IOException;
import java.time.LocalDate;
/*     */ import java.time.temporal.ChronoUnit;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/*     */ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.collections4.CollectionUtils;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.openqa.selenium.By;
/*     */ import org.openqa.selenium.WebElement;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.beans.factory.annotation.Value;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.CrossOrigin;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */
/*     */ @CrossOrigin
/*     */ @Controller
/*     */ public class AutoClickController {
    /*  33 */   private String originalWindow = "";
    /*     */
    /*     */   @Value("${vehicle.ui.days}")
    /*     */   private String uiDays;
    /*     */
    /*     */   @Value("${firefox.exe.path}")
    /*     */   private String firefoxPath;
    /*     */
    /*     */   @Value("${firefox.driver.path}")
    /*     */   private String fireDriverPath;
    /*     */
    /*     */   @Autowired
    /*     */   VehicleInfoService vehicleInfoService;
    /*     */
                public void getSystemDate(){
                    String serverTime = null;

                    try {
                        OkHttpClient client = new OkHttpClient().newBuilder().build();
                        Request request = new Request.Builder()
                                .url("http://172.26.249.20:9080/getSysTime")
                                .method("GET", null) // GET请求通常不需要设置RequestBody
                                .build();

                        Response response = client.newCall(request).execute();

                        // 检查响应状态码
                        if (!response.isSuccessful()) {
                            throw new IOException("Unexpected code " + response);
                        }

                        // 打印响应体

                        serverTime = response.body().string();
                        System.out.println("服务器时间：" + serverTime);

                    } catch (IOException e) {
                        // 使用日志框架记录异常信息
                        // log.error("Error occurred while making HTTP request", e);
                        System.out.println(e);
                        System.out.println("获取时间错误");
                        throw new RuntimeException(e);
                    }

                };
    /*     */   @GetMapping({"start_firefox"})
    /*     */   @ResponseBody
    /*     */   public String queryVehicleInfo(AutoClickForm form) {
                        System.out.println("进入方法");

        /*     */     try {
            /*  52 */       System.setProperty("webdriver.firefox.bin", this.firefoxPath);
            /*  53 */       System.setProperty("webdriver.gecko.driver", this.fireDriverPath);
            /*  55 */       FireFDriver.fDriver = null;
            /*  56 */       FireFDriver fireFDriver = FireFDriver.getFFDriver();
            /*  58 */       fireFDriver.manage().window().maximize();
            /*  60 */       fireFDriver.manage().timeouts().implicitlyWait(8L, TimeUnit.SECONDS);
            /*  63 */       fireFDriver.get("http://192.168.20.197:7000/");
            /*  64 */       fireFDriver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
            /*  65 */       this.originalWindow = fireFDriver.getWindowHandle();
            /*  68 */       WebElement loginLink = fireFDriver.findElement(By.linkText("机动车安全技术车检监管智能审核系统（统计查看数据）"));
            /*  69 */       loginLink.click();
            /*  70 */       fireFDriver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
            /*  73 */       for (String windowHandle : fireFDriver.getWindowHandles()) {
                /*  74 */         if (!this.originalWindow.contentEquals(windowHandle)) {
                    /*  75 */           fireFDriver.switchTo().window(windowHandle);
                    /*     */           break;
                    /*     */         }
                /*     */       }
            /*  81 */       Thread.sleep(3000L);
            /*  85 */       WebElement element = fireFDriver.findElement(By.cssSelector("#layout > section > header > div:nth-child(2) > a > i"));
            /*  86 */       element.click();
            /*  88 */       fireFDriver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
            /*  91 */       String dbVersion = form.getDatabaseVersion();
            /*  92 */       Map<String, Object> req = new HashMap<>();
            /*  93 */       req.put("isPass", "1");
            /*  94 */       req.put("center_status", "0");
            /*  95 */       req.put("created_at_gteq", LocalDate.now().minus(Long.valueOf(this.uiDays).longValue(), ChronoUnit.DAYS) + " 00:00:00");
            /*  96 */       req.put("created_at_lteq", LocalDate.now() + " 23:59:59");
            /*  97 */       List<VehicleInfo> vehicleInfos = new ArrayList<>();
            /*  98 */       if (StringUtils.isNotBlank(dbVersion) && dbVersion.equals(DataBaseVserionEnum.old_database_version.getCode())) {
                /*  99 */         vehicleInfos = this.vehicleInfoService.queryVehicleChecks(req);
                /*     */       } else {
                /* 101 */         vehicleInfos = this.vehicleInfoService.queryVehicleInfos(req);
                /*     */       }
            /* 103 */       while (CollectionUtils.isNotEmpty(vehicleInfos)) {
                /* 105 */         VehicleInfo vehicleInfo = vehicleInfos.get(0);
                /* 107 */         fireFDriver.navigate().refresh();
                /* 109 */         WebElement element1 = fireFDriver.findElement(By.cssSelector("#vehicle > form > div:nth-child(1) > div > div > div > input"));
                /* 110 */         element1.click();
                /* 111 */         fireFDriver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
                /* 113 */         WebElement element2 = fireFDriver.findElement(By.cssSelector("body > div.el-select-dropdown.el-popper > div.el-scrollbar > div.el-select-dropdown__wrap.el-scrollbar__wrap > ul > li:nth-child(2) > span"));
                /* 114 */         element2.click();
                /* 115 */         fireFDriver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
                /* 118 */         WebElement element3 = fireFDriver.findElement(By.cssSelector("#vehicle > form > div:nth-child(2) > div > div > input"));
                /* 119 */         element3.clear();
                /* 120 */         element3.sendKeys(new CharSequence[] { vehicleInfo.getHphm() });
                /* 121 */         fireFDriver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
                /* 124 */         WebElement element4 = fireFDriver.findElement(By.cssSelector("#vehicle > form > div:nth-child(4) > div > div > input:nth-child(2)"));
                /* 125 */         element4.click();
                /* 127 */         WebElement element5 = fireFDriver.findElement(By.cssSelector("body > div.el-picker-panel.el-date-range-picker.el-popper.has-time > div.el-picker-panel__footer > button.el-button.el-picker-panel__link-btn.el-button--text.el-button--mini > span"));
                /* 128 */         element5.click();
                /* 129 */         fireFDriver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
                /* 133 */         WebElement element6 = fireFDriver.findElement(By.cssSelector("#vehicle > form > div:nth-child(5) > div > button.el-button.el-button--primary.el-button--small > span"));
                /* 134 */         element6.click();
                /* 135 */         fireFDriver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
                /* 138 */         WebElement element7 = fireFDriver.findElement(By.cssSelector("#tableData > div.el-table__body-wrapper.is-scrolling-none > table > tbody > tr > td.el-table_1_column_1.is-center > div"));
                /* 139 */         element7.click();
                /* 140 */         fireFDriver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
                /* 142 */         Map<String, Object> update = new HashMap<>();
                /* 143 */         update.put("uuid", vehicleInfo.getId());
                /* 144 */         update.put("center_status", "1");
                /* 145 */         if (StringUtils.isNotBlank(dbVersion) && dbVersion.equals(DataBaseVserionEnum.old_database_version.getCode())) {
                    /* 146 */           this.vehicleInfoService.updateVehicleChecks(update);
                    /*     */         } else {
                    /* 148 */           this.vehicleInfoService.updateVehicleInfos(update);
                    /*     */         }
                /* 153 */         fireFDriver.navigate().back();
                /* 154 */         Thread.sleep(2000L);
                /* 155 */         if (StringUtils.isNotBlank(dbVersion) && dbVersion.equals(DataBaseVserionEnum.old_database_version.getCode())) {
                    /* 156 */           vehicleInfos = this.vehicleInfoService.queryVehicleChecks(req);
                    /*     */           continue;
                    /*     */         }
                /* 158 */         vehicleInfos = this.vehicleInfoService.queryVehicleInfos(req);
                /*     */       }
            /* 165 */       fireFDriver.close();
            /* 167 */       fireFDriver.switchTo().window(this.originalWindow);
            /* 181 */     } catch (InterruptedException e) {
            /* 182 */       e.printStackTrace();
            /*     */     }
        /* 184 */     return "success";
        /*     */   }
    /*     */
    /*     */   @RequestMapping({"/index"})
    /*     */   public String index(Model model) {
        /* 190 */     return "index";
        /*     */   }
    /*     */
    /*     */   @GetMapping({"stop_firefox"})
    /*     */   @ResponseBody
    /*     */   public List<VehicleInfo> queryVehicleChecks() {
        /* 196 */     FireFDriver fireFDriver = FireFDriver.getFFDriver();
        /* 197 */     fireFDriver.close();
        /* 198 */     fireFDriver.switchTo().window(this.originalWindow);
        /* 199 */     fireFDriver.close();
        /* 200 */     FireFDriver.fDriver = null;
        /* 201 */     return null;
        /*     */   }
    /*     */ }


/* Location:              /Users/zhao/Desktop/java/ui_32/旧JAR/vehicle-auto-click-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes/com/vehicle/auto/click/controller/AutoClickController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */